package com.pointi.sysChecker;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class sysCPU
{
	public String getCPU() throws SigarException
	{
		Sigar sigar = new Sigar() ;
		CpuPerc cpu = sigar.getCpuPerc() ; // TOTAL CPU INFO
		CpuPerc[] cpus = sigar.getCpuPercList() ; // EACH CPU INFO

		// PRINT
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss") ;
		String content = "" ;
		content += "(" + formatter.format(new Date()) + ") " ;
		content += "[CPU]" ;
		content += cpu_output(cpu) ;
		for(int i=0 ; i < cpus.length ; i++)
		{
			content += " (" + (i+1) + ")" ;
			content += cpu_output(cpus[i]) ;
		}
		return content ;
	}
	public String cpu_output(CpuPerc cpu)
	{
		String content = "" ;
		content += " USER: " + CpuPerc.format(cpu.getUser()) ;
		content += " SYSTEM: " + CpuPerc.format(cpu.getSys()) ;
		content += " IDLE: " + CpuPerc.format(cpu.getSys()) ;
		return content ;
	}
}
